﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Configuration;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using log4net;

namespace SEO.EmailSearch
{
    public partial class MainFrm : Form
    {
        delegate void SetTextCallback(string text);
        private Thread catchThread = null;
        public int iNum = 1;
        public string strDomain = "";
        SEO.Utility.IniFile iniFileVersion = new Utility.IniFile(Application.StartupPath + "\\version.ini");
        SEO.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
        SEO.Utility.IniFile iniFileDig = new Utility.IniFile(Application.StartupPath + "\\data\\website_dig.ini");
        SEO.Utility.IniFile iniFileDig1 = new Utility.IniFile(Application.StartupPath + "\\data\\website_dig1.ini");
        SEO.Utility.IniFile iniFileDig2 = new Utility.IniFile(Application.StartupPath + "\\data\\website_dig2.ini");
        SEO.Utility.IniFile iniFileDig3 = new Utility.IniFile(Application.StartupPath + "\\data\\website_dig3.ini");
        SEO.BLL.ESEmailsBLL emailbll = new BLL.ESEmailsBLL();
        SEO.BLL.ESKeywordsBLL keywordbll = new BLL.ESKeywordsBLL();
        SEO.DAL.ESKeywordsDAL keyworddal = new DAL.ESKeywordsDAL();

        public MainFrm()
        {
            InitializeComponent();
            
        }

        /// <summary>
        /// 显示实时消息到showMsg
        /// </summary>
        /// <param name="strMessage">实时消息</param>
        private void SetText(string strMessage)
        {
            if (this.showMsg.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { strMessage });
            }
            else
            {
                this.showMsg.Text = strMessage;
            }
        }

        /// <summary>
        /// 关闭整个应用程序进程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KillProcess(object sender, System.ComponentModel.CancelEventArgs e)
        {
            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }

        private void MainFrm_Load(object sender, EventArgs e)
        {


            SEO.Utility.LogHelper.WriteLog(typeof(MainFrm), "开始采集任务");
            //下面两句应该放在网站刚刚启动时加载,并放在一个静态方法里方便调用
            string strPath = Application.StartupPath + "\\App.config";
            strPath = strPath.Replace("\\bin\\Debug","");
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo((strPath)));
            ILog logAX = LogManager.GetLogger("logs");
            //写日志
            logAX.Error("Error AX");
            logAX.Info("Info AX");

        }

        /// <summary>
        /// 绑定电子邮件
        /// </summary>
        private void BindEmails()
        {
            emailbll.BindESEmailsBLL(dgvEmails2, "select * from Emails order by email_id desc");
        }

        /// <summary>
        /// 绑定关键词
        /// </summary>
        private void BindKeywords()
        {
            keywordbll.BindESKeywordsBLL(dgvKeywords, "select * from Keywords order by key_id");
        }

        private void btnAutoCatch_Click(object sender, EventArgs e)
        {
            //是否指定网址采集
            string strWebsite = txtUrl.Text.Trim();
            if (string.IsNullOrEmpty(strWebsite))
            {
                if (cbKeywords.Checked)
                {
                    //勾选关键词库
                    catchThread = new Thread(new ThreadStart(DoKeywordsGroupTask));
                    catchThread.Start();
                    btnAutoCatch.Enabled = false;
                    btnStop.Enabled = true;
                }
                else
                {
                    //没有勾选，单个关键词搜索
                    string strKeywords = txtKeywords.Text.Trim();
                    if (string.IsNullOrEmpty(strKeywords))
                    {
                        MessageBox.Show("请输入关键词！");
                        txtKeywords.Focus();
                    }
                    else
                    {
                        catchThread = new Thread(new ThreadStart(DoTask));
                        catchThread.Start();
                        //DoTask();
                        btnAutoCatch.Enabled = false;
                        btnStop.Enabled = true;
                        //存储关键词
                        iniFile.WriteValue("BASE", "KEYWORD", strKeywords);
                    }
                }
            }
            else
            {
                if (cbCache.Checked)
                {
                    //清除历史记录
                    iniFileDig.WriteValue("WEBSITES", "URLS", "");
                    iniFileDig1.WriteValue("WEBSITES", "URLS", "");
                    iniFileDig2.WriteValue("WEBSITES", "URLS", "");
                    iniFileDig3.WriteValue("WEBSITES", "URLS", "");
                }

                //指定网址采集
                catchThread = new Thread(new ThreadStart(DoWebsiteTask));
                catchThread.Start();
                btnAutoCatch.Enabled = false;
                btnStop.Enabled = true;
            }
        }

        /// <summary>
        /// 根据单个关键词采集邮件地址
        /// </summary>
        private void DoTask()
        {
            try
            {
                string strGetKeywords = txtKeywords.Text.Trim();
                bool bAPISoft = false;

                
                SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 开始采集任务...");
                this.SetText(SEO.Utility.PublicValue.GetMessage());

                #region 电子邮件采集
                string strPageNum = numUD.Value.ToString();
                string strGetGB22312String = "";
                //对汉字进行gb2312编码
                Byte[] encodedBytes = new byte[strGetKeywords.Length * 2];
                int iCount = Encoding.GetEncoding("gb2312").GetBytes(strGetKeywords, 0, strGetKeywords.Length, encodedBytes, 0);
                foreach (Byte b in encodedBytes)
                {
                    string strValue = Convert.ToString(b, 16);
                    strValue = strValue.ToUpper();
                    strGetGB22312String += "%" + strValue;
                }
                int m = 0;
                int n = 0;
                for (int k = 1; k <= int.Parse(strPageNum); k++)
                {
                    if (cbBaidu.Checked)
                    {
                        #region 百度
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        //string strBaiduUrl = "http://www.baidu.com/s?wd=" + strGetGB22312String + "%20email&pn=" + k + "0";
                        string strBaiduUrl = "http://www.baidu.com/s?wd=" + strGetKeywords + "&pn=" + k + "0&tn=baiduhome_pg&ie=utf-8&usm=2";
                        SEO.Spider.ESBaidu.AccordingURLGetNewsList(strBaiduUrl, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "百度", strGetKeywords, 0, "gb2312", bAPISoft);

                        //string strBaiduUrl2 = "http://www.baidu.com/s?wd=" + strGetGB22312String + "%20%D3%CA%CF%E4&pn=" + k + "0";
                        string strBaiduUrl2 = "http://www.baidu.com/s?wd=" + strGetKeywords + "%20email&pn=" + k + "0&tn=baiduhome_pg&ie=utf-8&usm=2";
                        SEO.Spider.ESBaidu.AccordingURLGetNewsList(strBaiduUrl2, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "百度", strGetKeywords, 0, "gb2312", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                        #endregion
                    }

                    if (cbSoso.Checked)
                    {
                        #region 搜搜
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集搜搜关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strSosoUrl = "http://www.soso.com/q?w=" + strGetGB22312String + "%20email&lr=&sc=web&ch=w.p&num=10&gid=&cin=&site=&sf=0&sd=0&pg=" + k;
                        SEO.Spider.ESSoso.AccordingURLGetNewsList(strSosoUrl, "<!--result list begin-->", "<!--result list end-->", showMsg, strGetKeywords, "搜搜", strGetKeywords, 0, "gb2312",bAPISoft);

                        string strSosoUrl2 = "http://www.soso.com/q?w=" + strGetGB22312String + "20%D3%CA%CF%E4&lr=&sc=web&ch=w.p&num=10&gid=&cin=&site=&sf=0&sd=0&pg=" + k;
                        SEO.Spider.ESSoso.AccordingURLGetNewsList(strSosoUrl2, "<!--result list begin-->", "<!--result list end-->", showMsg, strGetKeywords, "搜搜", strGetKeywords, 0, "gb2312",bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 搜搜【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                        #endregion
                    }

                    if (cbSogou.Checked)
                    {
                        #region 搜狗
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集搜狗关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strSogouUrl = "http://www.sogou.com/web?query=" + strGetGB22312String + "+email&page=" + k;
                        SEO.Spider.ESSogou.AccordingURLGetNewsList(strSogouUrl, "<!-- a -->", "<!-- z -->", showMsg, strGetKeywords, "搜狗", strGetKeywords, 0, "gb2312",bAPISoft);

                        string strSogouUrl2 = "http://www.sogou.com/web?query=" + strGetGB22312String + "+%D3%CA%CF%E4&page=" + k;
                        SEO.Spider.ESSogou.AccordingURLGetNewsList(strSogouUrl2, "<!-- a -->", "<!-- z -->", showMsg, strGetKeywords, "搜狗", strGetKeywords, 0, "gb2312",bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 搜狗【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                        #endregion
                    }

                    if (cbBing.Checked)
                    {
                        #region 必应
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集必应关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strBingUrl = "http://cn.bing.com/search?q=" + strGetGB22312String + "+email&go=&qs=n&sk=&first=" + k + "1&FORM=PORE";
                        SEO.Spider.ESBing.AccordingURLGetNewsList(strBingUrl, "<div id=\"results\">", "<div class=\"sb_pag\">", showMsg, strGetKeywords, "必应", strGetKeywords, 0, "utf-8",bAPISoft);

                        string strBingUrl2 = "http://cn.bing.com/search?q=" + strGetGB22312String + "+邮箱&go=&qs=n&sk=&first=" + k + "1&FORM=PORE";
                        SEO.Spider.ESBing.AccordingURLGetNewsList(strBingUrl2, "<div id=\"results\">", "<div class=\"sb_pag\">", showMsg, strGetKeywords, "必应", strGetKeywords, 0, "utf-8",bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 必应【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                        #endregion
                    }

                    if (cbGoogle.Checked)
                    {
                        #region 谷歌
                        m = n * 8;
                        if (m <= 56)
                        {
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集谷歌关键词【" + strGetKeywords + "，第" + m + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());


                            string strGoogleUrl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAApSs-g5KRxMRZvVRu1lLWaRTjvgUv2-2Hr4uupV2ZDRqQRMsErBQQ2qwKcM_00l7dQPTlRGzkthIviQ&rsz=large&q=" + strGetGB22312String + "%20%E9%82%AE%E7%AE%B1&start=" + m;
                            SEO.Spider.ESGoogle.AccordingURLGetNewsList(strGoogleUrl, "", "", showMsg, strGetKeywords, "谷歌", strGetKeywords, 0, "utf-8",bAPISoft);

                            string strGoogleUrl2 = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAApSs-g5KRxMRZvVRu1lLWaRTjvgUv2-2Hr4uupV2ZDRqQRMsErBQQ2qwKcM_00l7dQPTlRGzkthIviQ&rsz=large&q=" + strGetGB22312String + "%20email&start=" + m;
                            SEO.Spider.ESGoogle.AccordingURLGetNewsList(strGoogleUrl2, "", "", showMsg, strGetKeywords, "谷歌", strGetKeywords, 0, "utf-8",bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 谷歌【" + strGetKeywords + "，第" + m + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            n++;
                        }
                        #endregion
                    }

                    if (cb360.Checked)
                    {
                        #region 360搜索
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集360搜索关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string str360Url = "http://www.so.com/s?q=" + strGetGB22312String + "+email&pn=" + k + "&j=0&_re=0";
                        SEO.Spider.ES360.AccordingURLGetNewsList(str360Url, "<div id=\"m-spread-left\">", "<div id=\"side\">", showMsg, strGetKeywords, "360搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                        string str360Url2 = "http://www.so.com/s?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&pn=" + k + "&j=0&_re=0";
                        SEO.Spider.ES360.AccordingURLGetNewsList(str360Url2, "<div id=\"m-spread-left\">", "<div id=\"side\">", showMsg, strGetKeywords, "360搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 360搜索【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbBaiduTieba.Checked)
                    {
                        #region 百度贴吧
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度贴吧关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strBaiduTiebaUrl = "http://tieba.baidu.com/f/search/res?isnew=1&kw=&qw=" + strGetGB22312String + "%20email&rn=10&un=&sm=1&sd=&ed=&pn=" + k;
                        SEO.Spider.ESBaidutTieba.AccordingURLGetNewsList(strBaiduTiebaUrl, "<div class=\"s_post_list\">", "<div id=\"history_con\">", showMsg, strGetKeywords, "百度贴吧", strGetKeywords, 0, "gbk", bAPISoft);

                        string strBaiduTiebaUr2 = "http://tieba.baidu.com/f/search/res?isnew=1&kw=&qw=" + strGetGB22312String + "%20%D3%CA%CF%E4&rn=10&un=&sm=1&sd=&ed=&pn=" + k;
                        SEO.Spider.ESBaidutTieba.AccordingURLGetNewsList(strBaiduTiebaUr2, "<div class=\"s_post_list\">", "<div id=\"history_con\">", showMsg, strGetKeywords, "百度贴吧", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度贴吧【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbBaiduZhidao.Checked)
                    {
                        #region 百度知道
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度知道关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strBaiduZhidaoUrl = "http://zhidao.baidu.com/search?word=" + strGetGB22312String + "+email&lm=0&rn=10&sort=0&ie=gbk&pn=" + k;
                        SEO.Spider.ESBaiduZhidao.AccordingURLGetNewsList(strBaiduZhidaoUrl, "<dl class=\"result-item\">", "<div class=\"widget-pager clearfix\">", showMsg, strGetKeywords, "百度知道", strGetKeywords, 0, "gbk", bAPISoft);

                        string strBaiduZhidaoUrl2 = "http://zhidao.baidu.com/search?word=" + strGetGB22312String + "+%D3%CA%CF%E4&lm=0&rn=10&sort=0&ie=gbk&pn=" + k;
                        SEO.Spider.ESBaiduZhidao.AccordingURLGetNewsList(strBaiduZhidaoUrl2, "<dl class=\"result-item\">", "<div class=\"widget-pager clearfix\">", showMsg, strGetKeywords, "百度知道", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度知道【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbBaiduWenku.Checked)
                    {
                        #region 百度文库
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度文库关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strBaiduWenkuUrl = "http://wenku.baidu.com/search?word=" + strGetGB22312String + "+email&lm=0&od=0&pn=" + k;
                        SEO.Spider.ESBaiduWenku.AccordingURLGetNewsList(strBaiduWenkuUrl, "<div class=\"search-result\">", "<div class=\"page-nav page-center\">", showMsg, strGetKeywords, "百度文库", strGetKeywords, 0, "gbk", bAPISoft);

                        string strBaiduWenkuUrl2 = "http://wenku.baidu.com/search?word=" + strGetGB22312String + "+%D3%CA%CF%E4&lm=0&od=0&pn=" + k;
                        SEO.Spider.ESBaiduWenku.AccordingURLGetNewsList(strBaiduWenkuUrl2, "<div class=\"search-result\">", "<div class=\"page-nav page-center\">", showMsg, strGetKeywords, "百度文库", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度文库【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbYoudao.Checked)
                    {
                        #region 有道
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集有道关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        int page = k + 1;
                        int num = k * 10;
                        string strYoudaoUrl = "http://www.youdao.com/search?q=" + strGetGB22312String + "+email&start=" + num + "&ue=utf8&keyfrom=web.page" + page + "&lq=" + strGetGB22312String + "+email&timesort=0";
                        SEO.Spider.ESYoudao.AccordingURLGetNewsList(strYoudaoUrl, "<ol id=\"results\">", "<div class=\"c-pages\">", showMsg, strGetKeywords, "有道", strGetKeywords, 0, "gbk", bAPISoft);

                        string strYoudaoUrl2 = "http://www.youdao.com/search?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&start=" + num + "&ue=utf8&keyfrom=web.page" + page + "&lq=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&timesort=0";
                        SEO.Spider.ESYoudao.AccordingURLGetNewsList(strYoudaoUrl2, "<ol id=\"results\">", "<div class=\"c-pages\">", showMsg, strGetKeywords, "有道", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 有道【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    /*
                    if (cbYunyun.Checked)
                    {
                       //测试未成功
                        #region 云云
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集云云关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strYunyunUrl = "http://www.yunyun.com/Search.php?p=" + k + "&q=" + strGetKeywords + "%20email";
                        SEO.Spider.ESYunyun.AccordingURLGetNewsList(strYunyunUrl, "<div id=\"loading_image\"></div>", "<div id=\"yy_ft\">", showMsg, strGetKeywords, "云云", strGetKeywords, 0, "utf-8", bAPISoft);

                        string strYunyunUrl2 = "http://www.yunyun.com/Search.php?p=" + k + "&q=" + strGetKeywords + "%20%E9%82%AE%E7%AE%B1";
                        SEO.Spider.ESYunyun.AccordingURLGetNewsList(strYunyunUrl2, "<div id=\"loading_image\"></div>", "<div id=\"yy_ft\">", showMsg, strGetKeywords, "云云", strGetKeywords, 0, "utf-8", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 云云【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }*/

                    if (cbJike.Checked)
                    {
                        #region 即刻搜索
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集即刻搜索关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strJikeUrl = "http://www.jike.com/so?q=" + strGetGB22312String + "+email&page=" + k;
                        SEO.Spider.ESJike.AccordingURLGetNewsList(strJikeUrl, "<div class=\"Result\">", "<div id=\"pager\">", showMsg, strGetKeywords, "即刻搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                        string strJikeUrl2 = "http://www.jike.com/so?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&page=" + k;
                        SEO.Spider.ESJike.AccordingURLGetNewsList(strJikeUrl2, "<div class=\"Result\">", "<div id=\"pager\">", showMsg, strGetKeywords, "即刻搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 即刻搜索【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbKaixin.Checked)
                    {
                        #region 开心网
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集开心网关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strKaixinUrl = "http://www.baidu.com/s?wd=site%3Awww.kaixin001.com%20" + strGetKeywords + "%20email&pn=" + k + "0&ie=utf-8";
                        SEO.Spider.ESKaixin001.AccordingURLGetNewsList(strKaixinUrl, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "开心网", strGetKeywords, 0, "gb2312", bAPISoft);

                        string strKaixinUrl2 = "http://www.baidu.com/s?wd=site%3Awww.kaixin001.com%20" + strGetKeywords + "%20%E9%82%AE%E7%AE%B1&pn=" + k + "0&ie=utf-8";
                        SEO.Spider.ESKaixin001.AccordingURLGetNewsList(strKaixinUrl2, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "开心网", strGetKeywords, 0, "gb2312", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 开心网【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbWeibo.Checked)
                    {
                        #region 新浪微博
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集新浪微博关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                        if (k <= 1)
                        {
                            string strWeiboUrl = "http://s.weibo.com/weibo/" + strGetKeywords + "%2520email&Refer=index";
                            SEO.Spider.ESWeibo.AccordingURLGetNewsList(strWeiboUrl, "<div class=\"search_feed\">", "<!-- 未登录提示 -->", showMsg, strGetKeywords, "新浪微博", strGetKeywords, 0, "utf-8", bAPISoft);

                            string strWeiboUrl2 = "http://s.weibo.com/weibo/" + strGetKeywords + "%2520%25E9%2582%25AE%25E7%25AE%25B1&Refer=index";
                            SEO.Spider.ESWeibo.AccordingURLGetNewsList(strWeiboUrl2, "<div class=\"search_feed\">", "<!-- 未登录提示 -->", showMsg, strGetKeywords, "新浪微博", strGetKeywords, 0, "utf-8", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 新浪微博【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                        }

                        #endregion
                    }

                    if (cbHC360.Checked)
                    {
                        #region 慧聪网
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集慧聪网关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        int page = (k - 1) * 24 + 1;
                        //资讯
                        string strHC360Url = "http://s.hc360.com/info/" + strGetKeywords + "%20email.html?e=" + page + "&v=6";
                        SEO.Spider.ESHC360.AccordingURLGetNewsList(strHC360Url, "<!--news_list begin-->", "<!--list end-->", showMsg, strGetKeywords, "慧聪网(资讯)", strGetKeywords, 0, "gb2312", bAPISoft);

                        string strHC360Url2 = "http://s.hc360.com/info/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=6";
                        SEO.Spider.ESHC360.AccordingURLGetNewsList(strHC360Url2, "<!--news_list begin-->", "<!--list end-->", showMsg, strGetKeywords, "慧聪网(资讯)", strGetKeywords, 0, "gb2312", bAPISoft);

                        //供应
                        string strHC360Url3 = "http://s.hc360.com/supply/" + strGetKeywords + "%20email.html?e=" + page;
                        SEO.Spider.ESHC360Supply.AccordingURLGetNewsList(strHC360Url3, "<div class=\"search_List\">", "<div class=\"list_state\">", showMsg, strGetKeywords, "慧聪网(供应)", strGetKeywords, 0, "gb2312", bAPISoft);

                        string strHC360Url4 = "http://s.hc360.com/supply/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page;
                        SEO.Spider.ESHC360Supply.AccordingURLGetNewsList(strHC360Url4, "<div class=\"search_List\">", "<div class=\"list_state\">", showMsg, strGetKeywords, "慧聪网(供应)", strGetKeywords, 0, "gb2312", bAPISoft);

                        //求购
                        string strHC360Url5 = "http://s.hc360.com/buy/" + strGetKeywords + "%20email.html?e=" + page + "&v=2";
                        SEO.Spider.ESHC360Buy.AccordingURLGetNewsList(strHC360Url5, "<!--contenr start-->", "<!--contenr end-->", showMsg, strGetKeywords, "慧聪网(求购)", strGetKeywords, 0, "gb2312", bAPISoft);

                        string strHC360Url6 = "http://s.hc360.com/buy/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=2";
                        SEO.Spider.ESHC360Buy.AccordingURLGetNewsList(strHC360Url6, "<!--contenr start-->", "<!--contenr end-->", showMsg, strGetKeywords, "慧聪网(求购)", strGetKeywords, 0, "gb2312", bAPISoft);

                        //公司
                        string strHC360Url7 = "http://s.hc360.com/company/" + strGetKeywords + "%20email.html?e=" + page + "&v=4";
                        SEO.Spider.ESHC360Company.AccordingURLGetNewsList(strHC360Url7, "<!--company_list begin-->", "<!--pagination begin-->", showMsg, strGetKeywords, "慧聪网(公司)", strGetKeywords, 0, "gb2312", bAPISoft);

                        string strHC360Url8 = "http://s.hc360.com/company/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=4";
                        SEO.Spider.ESHC360Company.AccordingURLGetNewsList(strHC360Url8, "<!--company_list begin-->", "<!--pagination begin-->", showMsg, strGetKeywords, "慧聪网(公司)", strGetKeywords, 0, "gb2312", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 慧聪网【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbAlibaba.Checked)
                    {
                        #region 阿里巴巴
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集阿里巴巴关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strAlibabaUrl = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                        SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                        string strAlibabaUrl2 = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                        SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl2, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 阿里巴巴【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                    if (cbGooglePlay.Checked)
                    {
                        #region 谷歌Play
                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集阿里巴巴关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        string strAlibabaUrl = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                        SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                        string strAlibabaUrl2 = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                        SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl2, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                        SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 阿里巴巴【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                        this.SetText(SEO.Utility.PublicValue.GetMessage());

                        #endregion
                    }

                }
                
                #endregion

                //更新关键词状态
                keyworddal.UpdateKeywordsStatus(strGetKeywords);

                SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 采集任务完成！");
                this.SetText(SEO.Utility.PublicValue.GetMessage());
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("抓取任务 -> " + ex.Message);
            }

            btnAutoCatch.Enabled = true;
            btnStop.Enabled = false;
        }

        /// <summary>
        /// 根据关键词库采集邮件地址
        /// </summary>
        private void DoKeywordsGroupTask()
        {
            try
            {
                bool bAPISoft = false;

                List<SEO.Model.ESKeywords> list = new List<Model.ESKeywords>();
                list = keywordbll.GetESKeywordsByWhereBLL("select * from Keywords where catch_status=0 order by key_id");//测试
                if (list.Count == 0)
                {
                    //如果全部发布完毕，则更新所有邮件内容为未发布状态
                    SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 所有关键词分析完成！");
                    this.SetText(SEO.Utility.PublicValue.GetMessage());
                }
                foreach (SEO.Model.ESKeywords keyword in list)
                {
                    string strGetKeywords = keyword.KeyName.Trim();
                    int iGetKeyID = keyword.KeyID;

                    SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 开始分析关键词 -> " + strGetKeywords + " 搜索结果...");
                    this.SetText(SEO.Utility.PublicValue.GetMessage());

                    #region 电子邮件采集
                    string strPageNum = numUD.Value.ToString();
                    string strGetGB22312String = "";
                    //对汉字进行gb2312编码
                    Byte[] encodedBytes = new byte[strGetKeywords.Length * 2];
                    int iCount = Encoding.GetEncoding("gb2312").GetBytes(strGetKeywords, 0, strGetKeywords.Length, encodedBytes, 0);
                    foreach (Byte b in encodedBytes)
                    {
                        string strValue = Convert.ToString(b, 16);
                        strValue = strValue.ToUpper();
                        strGetGB22312String += "%" + strValue;
                    }

                    int m = 0;
                    int n = 0;
                    for (int k = 1; k <= int.Parse(strPageNum); k++)
                    {
                        if (cbBaidu.Checked)
                        {
                            #region 百度
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            //string strBaiduUrl = "http://www.baidu.com/s?wd=" + strGetGB22312String + "%20email&pn=" + k + "0";
                            string strBaiduUrl = "http://www.baidu.com/s?wd=" + strGetKeywords + "&pn=" + k + "0&tn=baiduhome_pg&ie=utf-8&usm=2";
                            SEO.Spider.ESBaidu.AccordingURLGetNewsList(strBaiduUrl, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "百度", strGetKeywords, 0, "gb2312", bAPISoft);

                            //string strBaiduUrl2 = "http://www.baidu.com/s?wd=" + strGetGB22312String + "%20%D3%CA%CF%E4&pn=" + k + "0";
                            string strBaiduUrl2 = "http://www.baidu.com/s?wd=" + strGetKeywords + "%20email&pn=" + k + "0&tn=baiduhome_pg&ie=utf-8&usm=2";
                            SEO.Spider.ESBaidu.AccordingURLGetNewsList(strBaiduUrl2, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "百度", strGetKeywords, 0, "gb2312", bAPISoft);


                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                            #endregion
                        }

                        if (cbSoso.Checked)
                        {
                            #region 搜搜
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集搜搜关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strSosoUrl = "http://www.soso.com/q?w=" + strGetGB22312String + "%20email&lr=&sc=web&ch=w.p&num=10&gid=&cin=&site=&sf=0&sd=0&pg=" + k;
                            SEO.Spider.ESSoso.AccordingURLGetNewsList(strSosoUrl, "<!--result list begin-->", "<!--result list end-->", showMsg, strGetKeywords, "搜搜", strGetKeywords, 0, "gb2312",bAPISoft);

                            string strSosoUrl2 = "http://www.soso.com/q?w=" + strGetGB22312String + "20%D3%CA%CF%E4&lr=&sc=web&ch=w.p&num=10&gid=&cin=&site=&sf=0&sd=0&pg=" + k;
                            SEO.Spider.ESSoso.AccordingURLGetNewsList(strSosoUrl2, "<!--result list begin-->", "<!--result list end-->", showMsg, strGetKeywords, "搜搜", strGetKeywords, 0, "gb2312",bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 搜搜【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                            #endregion
                        }

                        if (cbSogou.Checked)
                        {
                            #region 搜狗
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集搜狗关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strSogouUrl = "http://www.sogou.com/web?query=" + strGetGB22312String + "+email&page=" + k;
                            SEO.Spider.ESSogou.AccordingURLGetNewsList(strSogouUrl, "<div class=\"results\" >", "<table id=\"hint_container\" class=\"hint\">", showMsg, strGetKeywords, "搜狗", strGetKeywords, 0, "gb2312",bAPISoft);

                            string strSogouUrl2 = "http://www.sogou.com/web?query=" + strGetGB22312String + "+%D3%CA%CF%E4&page=" + k;
                            SEO.Spider.ESSogou.AccordingURLGetNewsList(strSogouUrl2, "<div class=\"results\" >", "<table id=\"hint_container\" class=\"hint\">", showMsg, strGetKeywords, "搜狗", strGetKeywords, 0, "gb2312",bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 搜狗【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                            #endregion
                        }

                        if (cbBing.Checked)
                        {
                            #region 必应
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集必应关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strBingUrl = "http://cn.bing.com/search?q=" + strGetGB22312String + "+email&go=&qs=n&sk=&first=" + k + "1&FORM=PORE";
                            SEO.Spider.ESBing.AccordingURLGetNewsList(strBingUrl, "<div id=\"results\">", "<div class=\"sb_pag\">", showMsg, strGetKeywords, "必应", strGetKeywords, 0, "utf-8",bAPISoft);

                            string strBingUrl2 = "http://cn.bing.com/search?q=" + strGetGB22312String + "+邮箱&go=&qs=n&sk=&first=" + k + "1&FORM=PORE";
                            SEO.Spider.ESBing.AccordingURLGetNewsList(strBingUrl2, "<div id=\"results\">", "<div class=\"sb_pag\">", showMsg, strGetKeywords, "必应", strGetKeywords, 0, "utf-8",bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 必应【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                            #endregion
                        }

                        if (cbGoogle.Checked)
                        {
                            #region 谷歌
                            m = n * 8;
                            if (m <= 56)
                            {
                                SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集谷歌关键词【" + strGetKeywords + "，第" + m + "页】搜索结果...");
                                this.SetText(SEO.Utility.PublicValue.GetMessage());


                                string strGoogleUrl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAApSs-g5KRxMRZvVRu1lLWaRTjvgUv2-2Hr4uupV2ZDRqQRMsErBQQ2qwKcM_00l7dQPTlRGzkthIviQ&rsz=large&q=" + strGetGB22312String + "%20%E9%82%AE%E7%AE%B1&start=" + m;
                                SEO.Spider.ESGoogle.AccordingURLGetNewsList(strGoogleUrl, "", "", showMsg, strGetKeywords, "谷歌", strGetKeywords, 0, "utf-8",bAPISoft);

                                string strGoogleUrl2 = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAApSs-g5KRxMRZvVRu1lLWaRTjvgUv2-2Hr4uupV2ZDRqQRMsErBQQ2qwKcM_00l7dQPTlRGzkthIviQ&rsz=large&q=" + strGetGB22312String + "%20email&start=" + m;
                                SEO.Spider.ESGoogle.AccordingURLGetNewsList(strGoogleUrl2, "", "", showMsg, strGetKeywords, "谷歌", strGetKeywords, 0, "utf-8",bAPISoft);

                                SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 谷歌【" + strGetKeywords + "，第" + m + "页】搜索结果采集结束！");
                                this.SetText(SEO.Utility.PublicValue.GetMessage());

                                n++;
                            }
                            #endregion
                        }

                        if (cb360.Checked)
                        {
                            #region 360搜索
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集360搜索关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string str360Url = "http://www.so.com/s?q=" + strGetGB22312String + "+email&pn=" + k + "&j=0&_re=0";
                            SEO.Spider.ES360.AccordingURLGetNewsList(str360Url, "<div id=\"m-spread-left\">", "<div id=\"side\">", showMsg, strGetKeywords, "360搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                            string str360Url2 = "http://www.so.com/s?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&pn=" + k + "&j=0&_re=0";
                            SEO.Spider.ES360.AccordingURLGetNewsList(str360Url2, "<div id=\"m-spread-left\">", "<div id=\"side\">", showMsg, strGetKeywords, "360搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 360搜索【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbBaiduTieba.Checked)
                        {
                            #region 百度贴吧
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度贴吧关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strBaiduTiebaUrl = "http://tieba.baidu.com/f/search/res?isnew=1&kw=&qw=" + strGetGB22312String + "%20email&rn=10&un=&sm=1&sd=&ed=&pn=" + k;
                            SEO.Spider.ESBaidutTieba.AccordingURLGetNewsList(strBaiduTiebaUrl, "<div class=\"s_post_list\">", "<div id=\"history_con\">", showMsg, strGetKeywords, "百度贴吧", strGetKeywords, 0, "gbk", bAPISoft);

                            string strBaiduTiebaUr2 = "http://tieba.baidu.com/f/search/res?isnew=1&kw=&qw=" + strGetGB22312String + "%20%D3%CA%CF%E4&rn=10&un=&sm=1&sd=&ed=&pn=" + k;
                            SEO.Spider.ESBaidutTieba.AccordingURLGetNewsList(strBaiduTiebaUr2, "<div class=\"s_post_list\">", "<div id=\"history_con\">", showMsg, strGetKeywords, "百度贴吧", strGetKeywords, 0, "gbk", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度贴吧【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbBaiduZhidao.Checked)
                        {
                            #region 百度知道
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度知道关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strBaiduZhidaoUrl = "http://zhidao.baidu.com/search?word=" + strGetGB22312String + "+email&lm=0&rn=10&sort=0&ie=gbk&pn=" + k;
                            SEO.Spider.ESBaiduZhidao.AccordingURLGetNewsList(strBaiduZhidaoUrl, "<dl class=\"result-item\">", "<div class=\"widget-pager clearfix\">", showMsg, strGetKeywords, "百度知道", strGetKeywords, 0, "gbk", bAPISoft);

                            string strBaiduZhidaoUrl2 = "http://zhidao.baidu.com/search?word=" + strGetGB22312String + "+%D3%CA%CF%E4&lm=0&rn=10&sort=0&ie=gbk&pn=" + k;
                            SEO.Spider.ESBaiduZhidao.AccordingURLGetNewsList(strBaiduZhidaoUrl2, "<dl class=\"result-item\">", "<div class=\"widget-pager clearfix\">", showMsg, strGetKeywords, "百度知道", strGetKeywords, 0, "gbk", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度知道【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbBaiduWenku.Checked)
                        {
                            #region 百度文库
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集百度文库关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strBaiduWenkuUrl = "http://wenku.baidu.com/search?word=" + strGetGB22312String + "+email&lm=0&od=0&pn=" + k;
                            SEO.Spider.ESBaiduWenku.AccordingURLGetNewsList(strBaiduWenkuUrl, "<div class=\"search-result\">", "<div class=\"page-nav page-center\">", showMsg, strGetKeywords, "百度文库", strGetKeywords, 0, "gbk", bAPISoft);

                            string strBaiduWenkuUrl2 = "http://wenku.baidu.com/search?word=" + strGetGB22312String + "+%D3%CA%CF%E4&lm=0&od=0&pn=" + k;
                            SEO.Spider.ESBaiduWenku.AccordingURLGetNewsList(strBaiduWenkuUrl2, "<div class=\"search-result\">", "<div class=\"page-nav page-center\">", showMsg, strGetKeywords, "百度文库", strGetKeywords, 0, "gbk", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 百度文库【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbYoudao.Checked)
                        {
                            #region 有道
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集有道关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            int page = k + 1;
                            int num = k * 10;
                            string strYoudaoUrl = "http://www.youdao.com/search?q=" + strGetGB22312String + "+email&start=" + num + "&ue=utf8&keyfrom=web.page" + page + "&lq=" + strGetGB22312String + "+email&timesort=0";
                            SEO.Spider.ESYoudao.AccordingURLGetNewsList(strYoudaoUrl, "<ol id=\"results\">", "<div class=\"c-pages\">", showMsg, strGetKeywords, "有道", strGetKeywords, 0, "gbk", bAPISoft);

                            string strYoudaoUrl2 = "http://www.youdao.com/search?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&start=" + num + "&ue=utf8&keyfrom=web.page" + page + "&lq=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&timesort=0";
                            SEO.Spider.ESYoudao.AccordingURLGetNewsList(strYoudaoUrl2, "<ol id=\"results\">", "<div class=\"c-pages\">", showMsg, strGetKeywords, "有道", strGetKeywords, 0, "gbk", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 有道【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbJike.Checked)
                        {
                            #region 即刻搜索
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集即刻搜索关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strJikeUrl = "http://www.jike.com/so?q=" + strGetGB22312String + "+email&page=" + k;
                            SEO.Spider.ESJike.AccordingURLGetNewsList(strJikeUrl, "<div class=\"Result\">", "<div id=\"pager\">", showMsg, strGetKeywords, "即刻搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                            string strJikeUrl2 = "http://www.jike.com/so?q=" + strGetGB22312String + "+%E9%82%AE%E7%AE%B1&page=" + k;
                            SEO.Spider.ESJike.AccordingURLGetNewsList(strJikeUrl2, "<div class=\"Result\">", "<div id=\"pager\">", showMsg, strGetKeywords, "即刻搜索", strGetKeywords, 0, "utf-8", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 即刻搜索【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbKaixin.Checked)
                        {
                            #region 开心网
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集开心网关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strKaixinUrl = "http://www.baidu.com/s?wd=site%3Awww.kaixin001.com%20" + strGetKeywords + "%20email&pn=" + k + "0&ie=utf-8";
                            SEO.Spider.ESKaixin001.AccordingURLGetNewsList(strKaixinUrl, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "开心网", strGetKeywords, 0, "gb2312", bAPISoft);

                            string strKaixinUrl2 = "http://www.baidu.com/s?wd=site%3Awww.kaixin001.com%20" + strGetKeywords + "%20%E9%82%AE%E7%AE%B1&pn=" + k + "0&ie=utf-8";
                            SEO.Spider.ESKaixin001.AccordingURLGetNewsList(strKaixinUrl2, "<div class=\"fsblock\">", "<p id=\"page\">", showMsg, strGetKeywords, "开心网", strGetKeywords, 0, "gb2312", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 开心网【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbWeibo.Checked)
                        {
                            #region 新浪微博
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集新浪微博关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());
                            if (k <= 1)
                            {
                                string strWeiboUrl = "http://s.weibo.com/weibo/" + strGetKeywords + "%2520email&Refer=index";
                                SEO.Spider.ESWeibo.AccordingURLGetNewsList(strWeiboUrl, "<div class=\"search_feed\">", "<!-- 未登录提示 -->", showMsg, strGetKeywords, "新浪微博", strGetKeywords, 0, "utf-8", bAPISoft);

                                string strWeiboUrl2 = "http://s.weibo.com/weibo/" + strGetKeywords + "%2520%25E9%2582%25AE%25E7%25AE%25B1&Refer=index";
                                SEO.Spider.ESWeibo.AccordingURLGetNewsList(strWeiboUrl2, "<div class=\"search_feed\">", "<!-- 未登录提示 -->", showMsg, strGetKeywords, "新浪微博", strGetKeywords, 0, "utf-8", bAPISoft);

                                SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 新浪微博【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                                this.SetText(SEO.Utility.PublicValue.GetMessage());
                            }

                            #endregion
                        }

                        if (cbHC360.Checked)
                        {
                            #region 慧聪网
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集慧聪网关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            int page = (k - 1) * 24 + 1;
                            //资讯
                            string strHC360Url = "http://s.hc360.com/info/" + strGetKeywords + "%20email.html?e=" + page + "&v=6";
                            SEO.Spider.ESHC360.AccordingURLGetNewsList(strHC360Url, "<!--news_list begin-->", "<!--list end-->", showMsg, strGetKeywords, "慧聪网(资讯)", strGetKeywords, 0, "gb2312", bAPISoft);

                            string strHC360Url2 = "http://s.hc360.com/info/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=6";
                            SEO.Spider.ESHC360.AccordingURLGetNewsList(strHC360Url2, "<!--news_list begin-->", "<!--list end-->", showMsg, strGetKeywords, "慧聪网(资讯)", strGetKeywords, 0, "gb2312", bAPISoft);

                            //供应
                            string strHC360Url3 = "http://s.hc360.com/supply/" + strGetKeywords + "%20email.html?e=" + page;
                            SEO.Spider.ESHC360Supply.AccordingURLGetNewsList(strHC360Url3, "<div class=\"search_List\">", "<div class=\"list_state\">", showMsg, strGetKeywords, "慧聪网(供应)", strGetKeywords, 0, "gb2312", bAPISoft);

                            string strHC360Url4 = "http://s.hc360.com/supply/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page;
                            SEO.Spider.ESHC360Supply.AccordingURLGetNewsList(strHC360Url4, "<div class=\"search_List\">", "<div class=\"list_state\">", showMsg, strGetKeywords, "慧聪网(供应)", strGetKeywords, 0, "gb2312", bAPISoft);

                            //求购
                            string strHC360Url5 = "http://s.hc360.com/buy/" + strGetKeywords + "%20email.html?e=" + page + "&v=2";
                            SEO.Spider.ESHC360Buy.AccordingURLGetNewsList(strHC360Url5, "<!--contenr start-->", "<!--contenr end-->", showMsg, strGetKeywords, "慧聪网(求购)", strGetKeywords, 0, "gb2312", bAPISoft);

                            string strHC360Url6 = "http://s.hc360.com/buy/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=2";
                            SEO.Spider.ESHC360Buy.AccordingURLGetNewsList(strHC360Url6, "<!--contenr start-->", "<!--contenr end-->", showMsg, strGetKeywords, "慧聪网(求购)", strGetKeywords, 0, "gb2312", bAPISoft);

                            //公司
                            string strHC360Url7 = "http://s.hc360.com/company/" + strGetKeywords + "%20email.html?e=" + page + "&v=4";
                            SEO.Spider.ESHC360Company.AccordingURLGetNewsList(strHC360Url7, "<!--company_list begin-->", "<!--pagination begin-->", showMsg, strGetKeywords, "慧聪网(公司)", strGetKeywords, 0, "gb2312", bAPISoft);

                            string strHC360Url8 = "http://s.hc360.com/company/" + strGetKeywords + "%20%D3%CA%CF%E4.html?e=" + page + "&v=4";
                            SEO.Spider.ESHC360Company.AccordingURLGetNewsList(strHC360Url8, "<!--company_list begin-->", "<!--pagination begin-->", showMsg, strGetKeywords, "慧聪网(公司)", strGetKeywords, 0, "gb2312", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 慧聪网【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }

                        if (cbAlibaba.Checked)
                        {
                            #region 阿里巴巴
                            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集阿里巴巴关键词【" + strGetKeywords + "，第" + k + "页】搜索结果...");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            string strAlibabaUrl = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                            SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                            string strAlibabaUrl2 = "http://search.china.alibaba.com/news/news_search.htm?keywords=" + strGetGB22312String + "+email&n=y&pageSize=20&beginPage=" + k;
                            SEO.Spider.ESAlibaba.AccordingURLGetNewsList(strAlibabaUrl2, "<div class=\"sw-layout-content\">", "<div class=\"pagination\">", showMsg, strGetKeywords, "阿里巴巴", strGetKeywords, 0, "gbk", bAPISoft);

                            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 阿里巴巴【" + strGetKeywords + "，第" + k + "页】搜索结果采集结束！");
                            this.SetText(SEO.Utility.PublicValue.GetMessage());

                            #endregion
                        }
                    }

                    #endregion

                    //更新关键词状态
                    keyworddal.UpdateKeywordsStatus(iGetKeyID);

                    SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 关键词 -> " + strGetKeywords + " 分析完成！");
                    this.SetText(SEO.Utility.PublicValue.GetMessage());
                }
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("根据关键词库采集邮件地址 -> " + ex.Message);
            }

            btnAutoCatch.Enabled = true;
            btnStop.Enabled = false;
        }

        private void DoWebsiteTask()
        {
            SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 开始采集任务...");
            this.SetText(SEO.Utility.PublicValue.GetMessage());

            try
            {
                int iDigNum = int.Parse(numericUpDownDig.Value.ToString());
                string strWebsite = txtUrl.Text.Trim();
                strDomain = strWebsite;
                if (iDigNum == 1)
                {
                    string strGetUrls = GetPageUrl(strWebsite);
                    iniFileDig1.WriteValue("WEBSITES", "URLS", strGetUrls);
                }
                if (iDigNum == 2)
                {
                    int a = 1;
                    while (a <= 3)
                    {
                        string strGetUrls = GetPageUrl(strWebsite);
                        iniFileDig1.WriteValue("WEBSITES", "URLS", strGetUrls);

                        if (a == 2)
                        {
                            //进行第2层挖掘
                            string strGetAllUrlDig2 = "";
                            //从第1层挖掘的地址中读取网址列表
                            string strGetDig1Urls = iniFileDig1.GetString("WEBSITES", "URLS", "");
                            string[] splitDig1Urls = strGetDig1Urls.Split(new char[] { '|' });
                            for (int i = 0; i < splitDig1Urls.Length; i++)
                            {
                                try
                                {
                                    string strGetWebsite = splitDig1Urls[i];
                                    if (SEO.Utility.CommonHelper.UrlIsExist(strGetWebsite) == 1)
                                    {
                                        string strGetUrls2 = GetPageUrl(strGetWebsite);
                                        strGetAllUrlDig2 = strGetUrls2 + "|";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SEO.Utility.Log.SaveErrorLog("分析单个网页 ->" + ex.Message);
                                }
                            }

                            strGetAllUrlDig2 = strGetAllUrlDig2.Substring(0, strGetAllUrlDig2.Length - 1);
                            iniFileDig2.WriteValue("WEBSITES", "URLS", strGetAllUrlDig2);
                        }
                        a++;
                    }
                }
                if (iDigNum == 3)
                {
                    int a = 1;
                    while (a < 4)
                    {
                        string strGetUrls = GetPageUrl(strWebsite);
                        iniFileDig1.WriteValue("WEBSITES", "URLS", strGetUrls);
                        if (a == 2)
                        {
                            //进行第2层挖掘
                            string strGetAllUrlDig2 = "";
                            //从第1层挖掘的地址中读取网址列表
                            string strGetDig1Urls = iniFileDig1.GetString("WEBSITES", "URLS", "");
                            string[] splitDig1Urls = strGetDig1Urls.Split(new char[] { '|' });
                            for (int i = 0; i < splitDig1Urls.Length; i++)
                            {
                                try
                                {
                                    string strGetWebsite = splitDig1Urls[i];
                                    if (SEO.Utility.CommonHelper.UrlIsExist(strGetWebsite) == 1)
                                    {
                                        string strGetUrls2 = GetPageUrl(strGetWebsite);
                                        strGetAllUrlDig2 = strGetUrls2 + "|";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SEO.Utility.Log.SaveErrorLog("分析单个网页 ->" + ex.Message);
                                }
                            }

                            strGetAllUrlDig2 = strGetAllUrlDig2.Substring(0, strGetAllUrlDig2.Length - 1);
                            iniFileDig2.WriteValue("WEBSITES", "URLS", strGetAllUrlDig2);
                        }
                        if (a == 3)
                        {
                            //进行第3层挖掘
                            string strGetAllUrlDig3 = "";
                            //从第1层挖掘的地址中读取网址列表
                            string strGetDig2Urls = iniFileDig2.GetString("WEBSITES", "URLS", "");
                            string[] splitDig2Urls = strGetDig2Urls.Split(new char[] { '|' });
                            for (int i = 0; i < splitDig2Urls.Length; i++)
                            {
                                try
                                {
                                    string strGetWebsite = splitDig2Urls[i];
                                    if (SEO.Utility.CommonHelper.UrlIsExist(strGetWebsite) == 1)
                                    {
                                        string strGetUrls2 = GetPageUrl(strGetWebsite);
                                        strGetAllUrlDig3 = strGetUrls2 + "|";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SEO.Utility.Log.SaveErrorLog("分析单个网页 ->" + ex.Message);
                                }
                            }

                            strGetAllUrlDig3 = strGetAllUrlDig3.Substring(0, strGetAllUrlDig3.Length - 1);
                            iniFileDig3.WriteValue("WEBSITES", "URLS", strGetAllUrlDig3);
                        }
                        a++;
                    }
                }

                //从分析出来的网址从过滤重复
                bool bAPISoft = false;

                string strGetNewUrls = "";
                string strGetNewUrls1 = iniFileDig1.GetString("WEBSITES", "URLS", "");
                string strGetNewUrls2 = iniFileDig2.GetString("WEBSITES", "URLS", "");
                string strGetNewUrls3 = iniFileDig3.GetString("WEBSITES", "URLS", "");

                if(iDigNum == 1)
                {
                    iniFileDig.WriteValue("WEBSITES", "URLS", strGetNewUrls1);
                }
                if (iDigNum == 2)
                {
                    string strGetSaveUrls = "";
                    strGetNewUrls = strGetNewUrls1 + "|" + strGetNewUrls2;
                    string[] splitUrls = strGetNewUrls.Split(new char[] { '|' });
                    for (int i = 0; i < splitUrls.Length;i++ )
                    {
                        string strUrl = splitUrls[i];
                        try
                        {
                            if (SEO.Utility.CommonHelper.UrlIsExist(strUrl) == 1)
                            {
                                if (!strGetSaveUrls.Contains(strUrl))
                                {
                                    strGetSaveUrls += strUrl + "|";
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SEO.Utility.Log.SaveErrorLog("分析有效网页 ->" + ex.Message);
                        }
                    }

                    strGetSaveUrls = strGetSaveUrls.Substring(0, strGetSaveUrls.Length - 1);
                    iniFileDig.WriteValue("WEBSITES", "URLS", strGetSaveUrls);
                }
                if (iDigNum == 3)
                {                 
                    string strGetSaveUrls = "";
                    strGetNewUrls = strGetNewUrls1 + "|" + strGetNewUrls2 + "|" + strGetNewUrls3;
                    string[] splitUrls = strGetNewUrls.Split(new char[] { '|' });
                    for (int i = 0; i < splitUrls.Length; i++)
                    {
                        string strUrl = splitUrls[i];
                        try
                        {
                            if (SEO.Utility.CommonHelper.UrlIsExist(strUrl) == 1)
                            {
                                if (!strGetSaveUrls.Contains(strUrl))
                                {
                                    strGetSaveUrls += strUrl + "|";
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SEO.Utility.Log.SaveErrorLog("分析有效网页 ->" + ex.Message);
                        }
                    }

                    strGetSaveUrls = strGetSaveUrls.Substring(0, strGetSaveUrls.Length - 1);
                    iniFileDig.WriteValue("WEBSITES", "URLS", strGetSaveUrls);
                }

                //开始分析邮件地址
                string strGetAllUrls = iniFileDig.GetString("WEBSITES", "URLS", "");
                string[] splitAllUrls = strGetAllUrls.Split(new char[] { '|' });
                for (int i = 0; i < splitAllUrls.Length; i++)
                {
                    string strUrl = splitAllUrls[i];
                    SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在采集邮件地址...");
                    this.SetText(SEO.Utility.PublicValue.GetMessage());

                    SEO.Spider.ESWebsite.AccordingURLGetNewsList(strUrl, "", "", showMsg, "",strDomain, "", 0, "utf-8", bAPISoft);

                    SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 邮件地址采集结束！");
                    this.SetText(SEO.Utility.PublicValue.GetMessage());
                }
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("分析网页URLs任务 ->" + ex.Message);
            }

            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 采集任务完成！");
            this.SetText(SEO.Utility.PublicValue.GetMessage());
        }

        public string GetPageUrl(string strWebsite)
        {
            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 正在分析网址:" + strWebsite);
            this.SetText(SEO.Utility.PublicValue.GetMessage());

            string strGetAllUrls = "";
            try
            {
                string pageHtml = GetPageHtml(strWebsite);
                string regex = "href=\"([^\"]*?)\"";
                
                Regex re = new Regex(regex);
                MatchCollection matches = re.Matches(pageHtml);
                System.Collections.IEnumerator enu = matches.GetEnumerator();
                while (enu.MoveNext() && enu.Current != null)
                {
                    Match match = (Match)(enu.Current);
                    string strUrl = match.ToString().Replace("href=\"/", strDomain + "/");
                    string strUrl2 = strUrl.Replace("href=", "");
                    string strUrl3 = strUrl2.Replace('"', ' ');
                    strUrl3 = strUrl3.Trim();

                    string strWebsite2 = strDomain + "/";
                    if (!strUrl3.Contains(".css") && !strUrl3.Contains(".swf") && !strUrl3.Contains(".js") && strUrl3.Length > 5 && strUrl3.Contains(strDomain) && strUrl3 != strDomain && strUrl3 != strWebsite2)
                    {
                        strGetAllUrls += strUrl3 + "|";

                        SEO.Utility.PublicValue.SaveMessage(Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 采集到网址: " + strUrl3);
                        this.SetText(SEO.Utility.PublicValue.GetMessage());
                    }
                }

                strGetAllUrls = strGetAllUrls.Substring(0, strGetAllUrls.Length - 1);
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("获取网页URLs ->" + ex.Message);
            }

            return strGetAllUrls;
        }

        public string GetPageHtml(string strUrl)
        {
            string strGetHtmlCode = "";

            try
            {
                SEO.Utility.WebClient wc = new SEO.Utility.WebClient();
                wc.Encoding = System.Text.Encoding.Default;
                wc.OpenRead(strUrl);
                strGetHtmlCode = wc.RespHtml;
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("获取网页源码 ->"+ex.Message);
            }

            return strGetHtmlCode;
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            SEO.Utility.PublicValue.SaveMessage("\r\n" + Convert.ToDateTime(DateTime.Now).ToString("MM-dd HH:mm:ss") + " 任务已停止！");
            this.SetText(SEO.Utility.PublicValue.GetMessage());

            btnAutoCatch.Enabled = true;
            btnStop.Enabled = false;
            if (catchThread.IsAlive)
            {
                catchThread.Abort();
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            catchThread = new Thread(new ThreadStart(BindEmails));
            catchThread.Start();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            catchThread = new Thread(new ThreadStart(ExportEmails));
            catchThread.Start();
        }

        private void ExportEmails()
        {
            try
            {
                string strGetEmails = "";
                List<SEO.Model.ESEmails> list = new List<Model.ESEmails>();
                list = emailbll.GetESEmailsByWhereBLL("select * from Emails order by email_id");
                foreach (SEO.Model.ESEmails email in list)
                {
                    string strEmail = email.EmailAddress;
                    if (!string.IsNullOrEmpty(strEmail))
                    {
                        string strValue = strEmail;
                        strGetEmails += strValue + "\r\n";
                    }
                }

                SEO.Utility.Log.SaveKeywords(strGetEmails, "emails_" + DateTime.Now.ToString("yyyyMMddHH"));

                //保存好后，打开
                System.Diagnostics.Process open = System.Diagnostics.Process.Start("notepad.exe", Application.StartupPath + "\\data\\emails_" + DateTime.Now.ToString("yyyyMMddHH") + ".txt");
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog(ex.Message);
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            btnDel.Text = "请稍等";
            btnDel.Enabled = false;
            try
            {
                for (int i = 0; i < dgvEmails2.Rows.Count; i++)//遍历dataGridView1中的所有行
                {
                    if (dgvEmails2.Rows[i].Cells[0].FormattedValue.ToString() == "True")//断定是否选中了该checkbox
                    {
                        string strGetID = dgvEmails2.Rows[i].Cells[1].FormattedValue.ToString();
                        emailbll.DeleteESEmailsBLL("delete from Emails where email_id=" + strGetID);
                    }
                }

                catchThread = new Thread(new ThreadStart(BindEmails));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("删除选中关键词-" + ex.Message);
            }
            btnDel.Text = "删除选中";
            btnDel.Enabled = true;
        }

        private void btnDelAll_Click(object sender, EventArgs e)
        {
            btnDelAll.Text = "请稍等";
            btnDelAll.Enabled = false;
            try
            {
                emailbll.DeleteESEmailsBLL("delete from Emails");
                catchThread = new Thread(new ThreadStart(BindEmails));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("删除所有数据 -> "+ex.Message);
            }
            btnDelAll.Text = "删除全部";
            btnDelAll.Enabled = true;
        }

        private void numUD_ValueChanged(object sender, EventArgs e)
        {
            //if (numUD.Value > 20)
            //{
            //    MessageBox.Show("免费版只支持抓取搜索引擎前20页数据，如果您需要更多的服务，请联系开发者！");
            //}
        }

        private void cbAllKeywords_CheckedChanged(object sender, EventArgs e)
        {
            dgvKeywords.Columns[0].DefaultCellStyle.NullValue = cbAllKeywords.Checked;
        }

        private void btnKeywordRefresh_Click(object sender, EventArgs e)
        {
            catchThread = new Thread(new ThreadStart(BindKeywords));
            catchThread.Start();
        }

        private void btnKeywordAdd_Click(object sender, EventArgs e)
        {
            KeywordAddFrm openWin = new KeywordAddFrm();
            openWin.Show();
        }

        private void btnKeywordImport_Click(object sender, EventArgs e)
        {
            KeywordImportFrm openWin = new KeywordImportFrm();
            openWin.Show();
        }

        private void btnKeywordDel_Click(object sender, EventArgs e)
        {
            btnKeywordDel.Text = "请稍等";
            btnKeywordDel.Enabled = false;
            try
            {
                for (int i = 0; i < dgvKeywords.Rows.Count; i++)//遍历dataGridView1中的所有行
                {
                    if (dgvKeywords.Rows[i].Cells[0].FormattedValue.ToString() == "True")//断定是否选中了该checkbox
                    {
                        //获取序号
                        string strGetNewsID = dgvKeywords.Rows[i].Cells[1].FormattedValue.ToString();
                        keywordbll.DeleteESKeywordsBLL("delete from Keywords where key_id=" + strGetNewsID);
                    }
                }

                //加载
                catchThread = new Thread(new ThreadStart(BindKeywords));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("删除选中关键词 -> " + ex.Message);
            }
            btnKeywordDel.Text = "删除选中";
            btnKeywordDel.Enabled = true;
        }

        private void btnKeywordDelAll_Click(object sender, EventArgs e)
        {
            btnKeywordDelAll.Text = "请稍等";
            btnKeywordDelAll.Enabled = false;
            try
            {
                keywordbll.DeleteESKeywordsBLL("delete from Keywords");
                catchThread = new Thread(new ThreadStart(BindKeywords));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("删除全部关键词 -> " + ex.Message);
            }
            btnKeywordDelAll.Text = "删除全部";
            btnKeywordDelAll.Enabled = true;
        }

        private void dgvEmails2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4 && e.RowIndex != -1)
            {
                string strGetUrl = dgvEmails2.Rows[e.RowIndex].Cells[6].FormattedValue.ToString();
                System.Diagnostics.Process.Start(strGetUrl);
            }
        }

        private void cbAllEmail_CheckedChanged(object sender, EventArgs e)
        {
            dgvEmails2.Columns[0].DefaultCellStyle.NullValue = cbAllEmail.Checked;
        }

        private void cbKeywords_CheckedChanged(object sender, EventArgs e)
        {
            if (cbKeywords.Checked)
            {
                txtKeywords.Text = "";
                txtKeywords.Enabled = false;
            }
            else
            {
                txtKeywords.Text = iniFile.GetString("BASE", "KEYWORD", "");
                txtKeywords.Enabled = true;
            }
        }

        private void llblSet_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            APISetFrm openWin = new APISetFrm();
            openWin.Show();
        }

        private void cbAPISoft_CheckedChanged(object sender, EventArgs e)
        {
            SEO.Spider.ESWebsite.AccordingURLGetNewsList("", "", "", showMsg, "", "阿里巴巴", "", 0, "utf-8", false);
        }

        private void btnKeywordCatched_Click(object sender, EventArgs e)
        {
            btnKeywordCatched.Text = "请稍等";
            btnKeywordCatched.Enabled = false;
            try
            {
                for (int i = 0; i < dgvKeywords.Rows.Count; i++)//遍历dataGridView1中的所有行
                {
                    if (dgvKeywords.Rows[i].Cells[0].FormattedValue.ToString() == "True")//断定是否选中了该checkbox
                    {
                        //获取序号
                        string strGetNewsID = dgvKeywords.Rows[i].Cells[1].FormattedValue.ToString();
                        keywordbll.DeleteESKeywordsBLL("update Keywords set catch_status=1 where key_id=" + strGetNewsID);
                    }
                }

                //加载
                catchThread = new Thread(new ThreadStart(BindKeywords));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("更新关键词已采集 -> " + ex.Message);
            }
            btnKeywordCatched.Text = "已采集";
            btnKeywordCatched.Enabled = true;
        }

        private void btnKeywordCatch_Click(object sender, EventArgs e)
        {
            btnKeywordCatch.Text = "请稍等";
            btnKeywordCatch.Enabled = false;
            try
            {
                for (int i = 0; i < dgvKeywords.Rows.Count; i++)//遍历dataGridView1中的所有行
                {
                    if (dgvKeywords.Rows[i].Cells[0].FormattedValue.ToString() == "True")//断定是否选中了该checkbox
                    {
                        //获取序号
                        string strGetNewsID = dgvKeywords.Rows[i].Cells[1].FormattedValue.ToString();
                        keywordbll.DeleteESKeywordsBLL("update Keywords set catch_status=0 where key_id=" + strGetNewsID);
                    }
                }

                //加载
                catchThread = new Thread(new ThreadStart(BindKeywords));
                catchThread.Start();
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("更新关键词未采集 -> " + ex.Message);
            }
            btnKeywordCatch.Text = "未采集";
            btnKeywordCatch.Enabled = true;
        }

        /// <summary>
        /// 检查软件是否有更新
        /// </summary>
        private void CheckSoftVersion()
        {
            try
            {
                string strNewVersion = SEO.Utility.SoftUpdate.GetNewVersionForEmailSearch();
                string strLocationVersion = iniFileVersion.GetString("cloudin_email_acquisition", "version", "");

                if (string.IsNullOrEmpty(strNewVersion))
                {
                    strLocationVersion = strNewVersion;
                }

                timerUpdate.Enabled = false;

                if (strNewVersion != strLocationVersion)
                {
                    //注意：‘提醒’两个字不能多，多了有异常错误。比如不能使,'云里提醒'
                    if (MessageBox.Show("检测到新版本，您是否需要更新？", "提醒", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.Hide();
                        UpdateFrm openWin = new UpdateFrm();
                        openWin.Show();
                    }
                }
                else
                {
                    this.Text = "SEOES " + strLocationVersion + "(已是最新版)";
                }
            }
            catch (Exception ex)
            {
                SEO.Utility.Log.SaveErrorLog("检查软件是否有更新 -> " + ex.Message);
            }

        }

        private void timerUpdate_Tick(object sender, EventArgs e)
        {
            //检测软件最新版本
            //CheckSoftVersion();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
    }
}
